/*
 * @Author: jiu yin
 * @Date: 2023-05-16 17:44:11
 * @LastEditTime: 2023-12-25 15:54:34
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \association-admin\src\utils\auth.js
 * jiu
 */



import { useSelector, useDispatch } from 'react-redux'
import { routerArrFilter } from "@/router";


//获取token
export const getToken = () => {
    return window.sessionStorage.getItem("token")
}
export const setToken = (str) => {
    return window.sessionStorage.setItem("token", str)
}

export function getUserInfo() {
    let userInfo = null
    if (window.sessionStorage.getItem("userInfo")) {
        userInfo = JSON.parse(window.sessionStorage.getItem("userInfo"))
    }
    return userInfo
}



export const butPermission = (str) => {
    //TODO 权限注释
    // const userInfo = useSelector((state) => state.user.userInfo)
    // // console.log(userInfo,"瓦迪斯");

    // if (!userInfo) return false
    // let roleListWrite = userInfo.roleListWrite
    // if (roleListWrite.length > 1) {
    //     return roleListWrite.includes(str)
    // } else {
    //     return false
    // }
    return true
}


//跳转到有权限的第一个路由
export const path_home = () => {
    // 这里是排除了首页 因为首页是0项
    routerArrFilter.shift()
    // 找有权限的第一项
    for (let i = 0, len = routerArrFilter.length; i < len; i++) {
        const item = routerArrFilter[i];
        let chi = item.children
        if(chi.length>0){
            let path= item.path+"/"+chi[0].path
            window.sessionStorage.setItem("path_home",path)
            return path
        }
    }
}